﻿using System;
using Microsoft.SharePoint.Administration;

namespace RahulBabar.SharePoint.Util.Extensions
{
	public class TimerJobUtils
	{
		/// <summary>
		/// Deletes all jobs in a web application by given name
		/// </summary>
		/// <param name="webApplication"></param>
		/// <param name="jobName"></param>
		private static void DeleteJob(this SPWebApplication webApplication, string jobName)
		{
			foreach (SPJobDefinition job in webApplication.JobDefinitions)
			{
				if (job.Name == jobName)
				{
					job.Delete();
				}
			}
		}

		/// <summary>
		/// Deletes all jobs in a web application by given type
		/// </summary>
		/// <param name="webApplication"></param>
		/// <param name="jobType"></param>
		private static void DeleteJob(SPWebApplication webApplication, Type jobType)
		{
			foreach (SPJobDefinition job in webApplication.JobDefinitions)
			{
				if (job.GetType().Equals(jobType))
				{
					job.Delete();
				}
			}
		}
	}
}
